<?php

/*
 * Create by Indonesian Brain Solutions
 * E-mail : cs@mesinit.com
 * Programmer : sony@sonywibisono.com
 */
class AssetParts {
    var $id;
    var $part_qty;
    var $condition;
    var $asset_id;
    var $parts_id;


    function open($id){
        global $db;
        $sql="select * from asset_parts where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->part_qty=$part_qty;
            $this->condition=$condition;
            $this->asset_id=$asset_id;
            $this->parts_id=$parts_id;

        }
    }

    function openAll(){
        $sql="select * from asset_parts order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into asset_parts values (null,'{$this->part_qty}',
'{$this->condition}','{$this->asset_id}','{$this->parts_id}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update asset_parts set part_qty='{$this->part_qty}',
condition='{$this->condition}',asset_id='{$this->asset_id}',
parts_id='{$this->parts_id}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from asset_parts where id=".$this->id;
        $db->query($sql);
    }

}
?>
